var _class, _temp;

import Taro from '@tarojs/taro-rn';
import * as tslib_1 from "tslib";
import React from 'react';
import { Component } from "@tarojs/taro-rn";
import { View, Image } from "@tarojs/components-rn";
import { toJS } from 'mobx';
import { inject, observer } from "@tarojs/mobx-rn";
import { getAvatar, getRuntime, subtime } from "../../utils/common";
import team_memberStyleSheet from "./team_member_styles";
var _styleSheet = team_memberStyleSheet;

let Company = (_temp = _class = class Company extends Component {
  constructor(props) {
    super(props);
    this.state = {
      id: null,
      totalCount: 0,
      items: {},
      fatherUser: {},
      userCount: Array(4).fill(0)
    };
  }
  componentWillMount() {
    Taro.setNavigationBarTitle({ title: '我的团队' });
    let id = parseInt(this.$router.params.id);
    if (!id) {
      getRuntime().navigateBack();
      return;
    }
    this.setState({
      id,
      fatherUser: getRuntime().getStorage('fatherUser')
    });
    this.getUserShareUsers(id);
  }
  // 获取推广用户列表
  getUserShareUsers(id) {
    let { userCount } = this.state;
    let { userStore } = this.props.stores;
    userStore.getUserShareUsers({
      formUserId: id,
      pageIndex: 1,
      pageSize: 200,
      callback: res => {
        // 统计数量
        res && res.items.map(item => {
          let pos = parseInt(item.agencyLevel);
          userCount.splice(pos, userCount[pos] + 1);
        });
        this.setState({
          totalCount: toJS(res.totalCount),
          items: toJS(res.items)
        });
      }
    });
  }
  handelRouter(url = '/pages/index/index') {
    getRuntime().navigateTo(url);
  }
  render() {
    let { totalCount, fatherUser, userCount } = this.state;
    return <View style={_styleSheet["my-my_team_member"]}>
        <View style={_styleSheet["list-20-item"]}>
          <Image src={getAvatar(fatherUser.avatar)} style={_styleSheet["img"]} />
          <View style={_styleSheet["info"]}>
            <View style={_styleSheet["list-title"]}>{fatherUser.name}</View>
            <View style={_styleSheet["tel"]}>{fatherUser.phoneNumber}</View>
            <View style={_styleSheet["list-info"]}>
              成为代理商时间：{subtime(fatherUser.creationTime)}
            </View>
          </View>
          <View style={_styleSheet["r"]}>共{totalCount}个成员</View>
        </View>
        <View style={_styleSheet["interval"]} />

        <View style={_styleSheet["item-member"]}>
          <View style={_styleSheet["list-title"]}>普通会员</View>
          <View style={_styleSheet["list-desc"]}>{userCount[0]}个</View>
        </View>

        <View style={_styleSheet["item-member"]}>
          <View style={_styleSheet["list-title"]}>VIP会员</View>
          <View style={_styleSheet["list-desc"]}>{userCount[1]}个</View>
        </View>

        <View style={_styleSheet["item-member"]}>
          <View style={_styleSheet["list-title"]}>代理商</View>
          <View style={_styleSheet["list-desc"]}>{userCount[2]}个</View>
        </View>

        <View style={_styleSheet["item-member"]}>
          <View style={_styleSheet["list-title"]}>合伙人</View>
          <View style={_styleSheet["list-desc"]}>{userCount[3]}个</View>
        </View>
      </View>;
  }
}, _class.config = {
  navigationBarTitleText: '下级成员'
}, _temp);
Company = tslib_1.__decorate([inject("stores"), observer], Company);
export default Company;